package com.wdf.dota;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Spanned;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

public class MyDialog extends Dialog {

    Context context;
   
    private String title;
    
    private Spanned content;
    

    
    private String action;
    
    private android.view.View.OnClickListener listener;
    
    private int width;
    
    private int height;
    private Window window = null;  
    
    public MyDialog(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        this.context = context;
    }
    public MyDialog(Context context, int theme){
        super(context, theme);
        this.context = context;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog);
    
		if(content !=null){
			TextView contentView = (TextView)findViewById(R.id.dialog_content_view);
			contentView.setText(""+content);
		}
		if(title !=null){
			
			TextView titleView = (TextView)findViewById(R.id.dialog_title_view);
			titleView.setText(""+title);
		}

		Button myPositiveButton = (Button)findViewById(R.id.dialog_button_ok);
		myPositiveButton.setText(action);
		myPositiveButton.setOnClickListener( listener);
		
		window =getWindow();
		
        Display display = window.getWindowManager().getDefaultDisplay();
        WindowManager.LayoutParams wl = window.getAttributes();  

         wl.width =(9*display.getWidth()/10);  
         wl.height =(2*display.getHeight())/3;  

        wl.gravity =Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;  
        window.setAttributes(wl);  
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    
    public void setProperty(int x,int y,int w,int h) {  
    
    	  width = w;
          height = h;
     }
    
    public void setProperty(int w,int h) {  
         width = w;
         height = h;
       }
    
    
	public void myHandler(View view) {

		switch (view.getId()) {
		case R.id.dialog_button_ok:
			
			super.dismiss();
			
			break;
		}
	}

	

	
	public Spanned getContent() {
		return content;
	}
	public void setContent(Spanned content) {
		this.content = content;
	}
	public void setPositiveButton(String action, final android.view.View.OnClickListener listener){
		 this.action = action;
		 this.listener = listener;
	}
	
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public void cancel(){
		
	}
	
}